﻿function AddUserToGroup() {
    $.ajax({ type: 'POST',
        contentType: 'application/json',
        url: relRootPath + '/Services/GroupServices.asmx/AddUserToGroup',
        data: "{ 'groupid': '" + groupid + "', 'userid':'" + userid + "' }",
        dataType: 'json',
        success: function(result) {
            if (result.d) {
                $('div#joingroupsuccess').css("display", "");
            }
        },
        error: function(result, status) {
            alert(result.d);
        }
    }
    );
}

$(function () {
    $('a.addusertogroupbutton').click(AddUserToGroup);
    $('div#prerequest').show();
    $('div#postrequest').hide();
    $('#joingrouprequestbutton').click(SendJoinGroupRequest);
});

function SendJoinGroupRequest() {
    $.post(
    relRootPath + '/Services/GroupServices.asmx/JoinGroupRequest',
    { groupId: groupid, groupName: groupname, comment: $('.requestcomment').val(), userId: userid },
    SendRequestSuccess
    );
}

function SendRequestSuccess(d, s, x) {

    var success = eval($(d).text());
    if (success) {
        $('div#prerequest').hide();
        $('div#postrequest').show();
    }
    else {
        alert("抱歉，服务器错误。");
    }
}